From 4ab58e0a4c76ace1be3ac6a9dca6925bda0be324 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 31 Jan 2008 06:32:58 +0000 Subject: [PATCH] Add option to KML writer to show direction of motion on track logs. --- internal_styles.c | 70 ++++++++++++++++---------------- kml.c | 75 +++++++++++++++++++++++++---------- reference/earth-expertgps.kml | 10 ++--- 3 files changed, 95 insertions(+), 60 deletions(-) diff --git a/internal_styles.c b/internal_styles.c index 2bd6f95ed..7c1a534ef 100644 --- a/internal_styles.c +++ b/internal_styles.c @@ -997,6 +997,40 @@ static char tomtom_itn[] = "IFIELD SHORTNAME, \"\", \"%s\"\n" "IFIELD CONSTANT, \"0\", \"%s\"\n" ; +static char xmap[] = +"# gpsbabel XCSV style file\n" +"#\n" +"# Format: DeLorme Xmap Conduit\n" +"# Author: Alex Mottram\n" +"# Date: 12/09/2002\n" +"#\n" +"# \n" +"# As defined in csv.c/xmap\n" +"#\n" + +"DESCRIPTION DeLorme XMap HH Native .WPT\n" +"EXTENSION wpt\n" + +"#\n" +"# FILE LAYOUT DEFINITIIONS:\n" +"#\n" +"FIELD_DELIMITER COMMASPACE\n" +"RECORD_DELIMITER NEWLINE\n" +"BADCHARS COMMA\n" + +"PROLOGUE BEGIN SYMBOL\n" +"EPILOGUE END\n" +"#\n" +"# INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE:\n" +"#\n" +"IFIELD LAT_HUMAN_READABLE, \"\", \"%08.5f\"\n" +"IFIELD LON_HUMAN_READABLE, \"\", \"%08.5f\"\n" +"IFIELD DESCRIPTION, \"\", \"%s\"\n" + +"OFIELD LAT_DECIMAL, \"\", \"%08.5f\"\n" +"OFIELD LON_DECIMAL, \"\", \"%08.5f\"\n" +"OFIELD DESCRIPTION, \"\", \"%s\"\n" +; static char xmap2006[] = "# gpsbabel XCSV style file\n" "#\n" @@ -1035,40 +1069,6 @@ static char xmap2006[] = -; -static char xmap[] = -"# gpsbabel XCSV style file\n" -"#\n" -"# Format: DeLorme Xmap Conduit\n" -"# Author: Alex Mottram\n" -"# Date: 12/09/2002\n" -"#\n" -"# \n" -"# As defined in csv.c/xmap\n" -"#\n" - -"DESCRIPTION DeLorme XMap HH Native .WPT\n" -"EXTENSION wpt\n" - -"#\n" -"# FILE LAYOUT DEFINITIIONS:\n" -"#\n" -"FIELD_DELIMITER COMMASPACE\n" -"RECORD_DELIMITER NEWLINE\n" -"BADCHARS COMMA\n" - -"PROLOGUE BEGIN SYMBOL\n" -"EPILOGUE END\n" -"#\n" -"# INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE:\n" -"#\n" -"IFIELD LAT_HUMAN_READABLE, \"\", \"%08.5f\"\n" -"IFIELD LON_HUMAN_READABLE, \"\", \"%08.5f\"\n" -"IFIELD DESCRIPTION, \"\", \"%s\"\n" - -"OFIELD LAT_DECIMAL, \"\", \"%08.5f\"\n" -"OFIELD LON_DECIMAL, \"\", \"%08.5f\"\n" -"OFIELD DESCRIPTION, \"\", \"%s\"\n" ; static char xmapwpt[] = "# gpsbabel XCSV style file\n" @@ -1102,7 +1102,7 @@ static char xmapwpt[] = "IFIELD IGNORE, \"\", \"%-.31s\"\n" "IFIELD DESCRIPTION, \"\", \"%-.78s\"\n" ; -style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "xmap2006", xmap2006 } , { "tomtom_itn", tomtom_itn } , { "tomtom_asc", tomtom_asc } , { "tabsep", tabsep } , { "sportsim", sportsim } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "openoffice", openoffice } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "kwf2", kwf2 } , { "ktf2", ktf2 } , { "kompass_wp", kompass_wp } , { "kompass_tk", kompass_tk } , { "gpsman", gpsman } , { "gpsdrivetrack", gpsdrivetrack } , { "gpsdrive", gpsdrive } , { "geonet", geonet } , { "garmin_poi", garmin_poi } , { "garmin301", garmin301 } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "cup", cup } , { "csv", csv } , { "cambridge", cambridge } , { "arc", arc } , {0,0}}; +style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap2006", xmap2006 } , { "xmap", xmap } , { "tomtom_itn", tomtom_itn } , { "tomtom_asc", tomtom_asc } , { "tabsep", tabsep } , { "sportsim", sportsim } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "openoffice", openoffice } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "kwf2", kwf2 } , { "ktf2", ktf2 } , { "kompass_wp", kompass_wp } , { "kompass_tk", kompass_tk } , { "gpsman", gpsman } , { "gpsdrivetrack", gpsdrivetrack } , { "gpsdrive", gpsdrive } , { "geonet", geonet } , { "garmin_poi", garmin_poi } , { "garmin301", garmin301 } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "cup", cup } , { "csv", csv } , { "cambridge", cambridge } , { "arc", arc } , {0,0}}; size_t nstyles = 30; #else /* CSVFMTS_ENABLED */ style_vecs_t style_list[] = {{0,0}}; diff --git a/kml.c b/kml.c index 55a7d20cc..88dffe405 100644 --- a/kml.c +++ b/kml.c @@ -36,6 +36,7 @@ static char *opt_line_color = NULL; static char *opt_floating = NULL; static char *opt_extrude = NULL; static char *opt_trackdata = NULL; +static char *opt_trackdirection = NULL; static char *opt_units = NULL; static char *opt_labels = NULL; static char *opt_max_position_points = NULL; @@ -45,6 +46,7 @@ static int export_points; static int floating; static int extrude; static int trackdata; +static int trackdirection; static int max_position_points; static int indent_level; @@ -66,7 +68,8 @@ typedef enum { kmlpt_unknown, kmlpt_waypoint, kmlpt_track, - kmlpt_route + kmlpt_route, + kmlpt_other } kml_point_type; static int point3d_list_len; @@ -105,7 +108,7 @@ arglist_t kml_args[] = { "6", ARGTYPE_INT, ARG_NOMINMAX }, {"line_color", &opt_line_color, "Line color, specified in hex AABBGGRR", - "64eeee17", ARGTYPE_STRING, ARG_NOMINMAX }, + "99ffac59", ARGTYPE_STRING, ARG_NOMINMAX }, {"floating", &opt_floating, "Altitudes are absolute and not clamped to ground", "0", ARGTYPE_BOOL, ARG_NOMINMAX }, @@ -115,6 +118,9 @@ arglist_t kml_args[] = { {"trackdata", &opt_trackdata, "Include extended data for trackpoints (default = 1)", "1", ARGTYPE_BOOL, ARG_NOMINMAX }, + {"trackdirection", &opt_trackdirection, + "Indicate direction of travel in track icons (default = 0)", + "0", ARGTYPE_BOOL, ARG_NOMINMAX }, {"units", &opt_units, "Units used when writing comments ('s'tatute or 'm'etric)", "s", ARGTYPE_STRING, ARG_NOMINMAX }, @@ -132,15 +138,16 @@ struct { int freshness; char *icon; } kml_tracking_icons[] = { - { 60, "http://maps.google.com/mapfiles/kml/pal4/icon15.png" }, // Red - { 30, "http://maps.google.com/mapfiles/kml/pal4/icon31.png" }, // Yellow - { 0, "http://maps.google.com/mapfiles/kml/pal4/icon62.png" }, // Green + { 60, "http://www.gpsbabel.org/apps/earth/youarehere-60.png" }, // Red + { 30, "http://www.gpsbabel.org/apps/earth/youarehere-30.png" }, // Yellow + { 0, "http://www.gpsbabel.org/apps/earth/youarehere-0.png" }, // Green }; -#define ICON_NOSAT "http://maps.google.com/mapfiles/kml/pal3/icon59.png"; +#define ICON_NOSAT "http://www.gpsbabel.org/apps/earth//youarehere-warning.png"; #define ICON_WPT "http://maps.google.com/mapfiles/kml/pal4/icon61.png" -#define ICON_TRK "http://maps.google.com/mapfiles/kml/pal4/icon60.png" -#define ICON_RTE "http://maps.google.com/mapfiles/kml/pal4/icon61.png" +#define ICON_TRK "http://www.gpsbabel.org/apps/earth/track-directional/track-none.png" +#define ICON_RTE "http://www.gpsbabel.org/apps/earth/track-directional/track-none.png" +#define ICON_DIR "http://www.gpsbabel.org/apps/earth/track-directional/track-%d.png" // format string where next arg is rotational degrees. #define MYNAME "kml" @@ -415,13 +422,15 @@ static void kml_write_bitmap_style_(const char *style, const char * bitmap, * and non-highlighted version of the style to allow the icons * to magnify slightly on a rollover. */ -static void kml_write_bitmap_style(kml_point_type pt_type, const char *bitmap) +static void kml_write_bitmap_style(kml_point_type pt_type, const char *bitmap, + const char *customstyle) { - char *style; + const char *style; switch (pt_type) { case kmlpt_track: style = "track"; break; case kmlpt_route: style = "route"; break; case kmlpt_waypoint: style = "waypoint"; break; + case kmlpt_other: style = customstyle; break; default: fatal("kml_output_point: unknown point type"); break; } @@ -636,6 +645,12 @@ static void kml_output_point(const waypoint *waypointp, kml_point_type pt_type) default: fatal("kml_output_point: unknown point type"); break; } + switch (pt_type) { + case kmlpt_track: style = "#track"; break; + case kmlpt_route: style = "#route"; break; + default: fatal("kml_output_point: unknown point type"); break; + } + pt->longitude = waypointp->longitude; pt->latitude = waypointp->latitude; pt->altitude = waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude; @@ -649,13 +664,19 @@ static void kml_output_point(const waypoint *waypointp, kml_point_type pt_type) kml_output_description(waypointp); kml_output_lookat(waypointp); kml_output_timestamp(waypointp); - kml_write_xml(0, "%s\n", style); -#if 0 - // If we were to try to spin track icon to indication direction - // of motion, it might look something like this. Unfortunately, - // doing that causes a huge performance problem in Google Earth. - kml_write_xml(0, "\n", 360 - waypointp->course); -#endif + + if (trackdirection && (pt_type == kmlpt_track)) { + char buf[100]; + if (waypointp->speed < 1) + snprintf(buf, sizeof(buf), "%s-none", style); + else + snprintf(buf, sizeof(buf), "%s-%d", style, + (int) (waypointp->course / 22.5 + .5) % 16); + kml_write_xml(0, "%s\n", buf); + } else { + kml_write_xml(0, "%s\n", style); + } + kml_write_xml(1, "\n"); if (floating) { kml_write_xml(0, "absolute\n"); @@ -1005,6 +1026,7 @@ void kml_write(void) floating = (!! strcmp("0", opt_floating)); extrude = (!! strcmp("0", opt_extrude)); trackdata = (!! strcmp("0", opt_trackdata)); + trackdirection = (!! strcmp("0", opt_trackdirection)); kml_write_xml(0, "\n"); @@ -1036,14 +1058,27 @@ void kml_write(void) // Style settings for bitmaps if (route_waypt_count()) { - kml_write_bitmap_style(kmlpt_route, ICON_RTE); + kml_write_bitmap_style(kmlpt_route, ICON_RTE, NULL); } if (track_waypt_count()) { - kml_write_bitmap_style(kmlpt_track, ICON_TRK); + if (trackdirection) { + int i; + kml_write_bitmap_style(kmlpt_other, ICON_TRK, "track-none"); + for (i = 0; i < 16; i++) { + char buf1[100]; + char buf2[100]; + + sprintf(buf1, "track-%d", i); + sprintf(buf2, ICON_DIR, i); + kml_write_bitmap_style(kmlpt_other, buf2, buf1); + } + } else { + kml_write_bitmap_style(kmlpt_track, ICON_TRK, NULL); + } } - kml_write_bitmap_style(kmlpt_waypoint, ICON_WPT); + kml_write_bitmap_style(kmlpt_waypoint, ICON_WPT, NULL); if (track_waypt_count() || route_waypt_count()) { // Style settings for line strings diff --git a/reference/earth-expertgps.kml b/reference/earth-expertgps.kml index 5756e1ce2..946c8f263 100644 --- a/reference/earth-expertgps.kml +++ b/reference/earth-expertgps.kml @@ -7,7 +7,7 @@ @@ -16,7 +16,7 @@ 1.2 - http://maps.google.com/mapfiles/kml/pal4/icon61.png + http://www.gpsbabel.org/apps/earth/track-directional/track-none.png @@ -34,7 +34,7 @@ @@ -43,7 +43,7 @@ 1.2 - http://maps.google.com/mapfiles/kml/pal4/icon60.png + http://www.gpsbabel.org/apps/earth/track-directional/track-none.png @@ -86,7 +86,7 @@ -- 2.30.2